'''
# @Title:
# @Time : 2022/3/2 15:27
# @File : mitmRewrite.py
# @Software: PyCharm

'''
import json

from mitmproxy import http

class MitmRewrite:

    def response(self,flow:http.HTTPFlow):

        if "quote.json" in flow.request.pretty_url:

            data = json.loads(flow.response.content)

            # 修改数据
            data["data"]["items"][0]["quote"]["percent"] = "-0.01"
            data["data"]["items"][1]["quote"]["percent"] = "0.00"
            data["data"]["items"][2]["quote"]["percent"] = "0.01"

            flow.response.text = json.dumps(data)


addons = [
    MitmRewrite()
]